package com.it.jdbc;

import com.it.jdbc.druid.JdbcUtils;
import com.it.jdbc.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.Statement;

/**
 * 通过jdbc工具类来实现数据的增删改查
 */
public class JdbcDemo02 {
    public static void main(String[] args) throws Exception{
        //1.添加操作
        //驱动的注册、连接的获取、资源的关闭都不需要创建了
        //获取数据库的连接
        //Connection connection = JDBCUtils.getConnection();
        //使用连接池的方式
        Connection connection = JdbcUtils.getConnection();
        //进行手动提交事务
        //connection.setAutoCommit(false);
        //编写sql
        String sql = "insert into account values (null,'王菲',8000)";
        //获取statement
        Statement statement = connection.createStatement();
        //执行sql
        int count = statement.executeUpdate(sql);
        //connection.commit();
        //connection.rollback();
        System.out.println(count);
        //关闭资源
        JDBCUtils.close(null,statement,connection);
    }
}
